package com.plusjun.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.plusjun.gulimall.order.config.AlipayTemplate;
import com.plusjun.gulimall.order.service.OrderService;
import com.plusjun.gulimall.order.vo.PayVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class PayController {

    @Resource
    private OrderService orderService;

    @Resource
    private AlipayTemplate alipayTemplate;

    @GetMapping(value = "/payOrder",produces = "text/html")
    @ResponseBody
    public String payOrder(@RequestParam("orderSn")String orderSn) throws AlipayApiException {
        PayVo orderPay = orderService.getOrderPay(orderSn);
        // 将此页面交给浏览器
        String pay = alipayTemplate.pay(orderPay);

        return pay;
    }
}
